<!DOCTYPE html>
<html>
<head>
    <meta name="layout" content="main"/>
    <g:set var="entityName" value="${message(code: 'product.label', default: 'Product')}"/>
    <title>产品：${this.product.name}</title>
</head>

<body class="fixed-navbar fixed-sidebar">
<div class="small-header">
    <div class="hpanel">
        <div class="panel-body">
            <div id="hbreadcrumb" class="pull-right">
                <ol class="hbreadcrumb breadcrumb">
                    <li>贷款管理系统</li>
                    <li>
                        <g:link controller="product" action="index">产品管理</g:link>
                    </li>
                    <li class="active">
                        <span>${this.product.name}</span>
                    </li>
                </ol>
            </div>

            <h2 class="font-light m-b-xs" style="text-transform:none;">
                产品: ${this.product.name}
            </h2>
        </div>
    </div>
</div>

<div class="content animate-panel">
    <div class="row">
        <div class="hpanel hblue">
            <div class="panel-heading">
                产品信息编辑
            </div>

            <div class="panel-body">
                <g:form resource="${this.product}" method="PUT" class="form-horizontal productForm">
                    <g:if test="${flash.message}">
                        <div class="message" role="status">${flash.message}</div>
                    </g:if>
                    <g:hasErrors bean="${this.product}">
                        <ul class="errors" role="alert">
                            <g:eachError bean="${this.product}" var="error">
                                <li <g:if test="${error in org.springframework.validation.FieldError}">data-field-id="${error.field}"</g:if>>
                                    <g:message error="${error}"/>
                                </li>
                            </g:eachError>
                        </ul>
                    </g:hasErrors>
                    <div class="form-group">
                        <label class="col-md-3 control-label">产品名称</label>

                        <div class="col-md-3">
                            <g:textField name="name" value="${this.product?.name}" class="form-control"/>
                        </div>

                    </div>

                    <div class="hr-line-dashed"></div>
                    <div class="form-group">

                        <label class="col-md-3 control-label">有效性</label>

                        <div class="col-md-1">
                            <g:checkBox name="active" value="${this.product?.active}" class="form-control"
                                        style="height:16px;margin-top: 10px"/>
                        </div>
                    </div>

                    <div class="hr-line-dashed"></div>

                    <div class="form-group">
                        <label class="col-md-3 control-label">产品类别</label>

                        <div class="col-md-3">
                            <g:select name="category.id" value="${this.product?.category?.id}"
                                      from="${com.next.ProductCategory.list()}" optionKey="id" optionValue="name"
                                      class="form-control"/>
                        </div>

                    </div>
                    <div class="hr-line-dashed"></div>

                    <div class="form-group">
                        <label class="col-md-3 control-label">贷款成数</label>

                        <div class="col-md-3 input-group">
                            <input class="form-control" name="loanToValue" type="text"
                                   value="<g:formatNumber number="${this.product?.loanToValue}" type="number" maxFractionDigits="2"
                                            minFractionDigits="2"/>">
                            <span class="input-group-addon">%</span>

                        </div>

                    </div>
                    <div class="hr-line-dashed"></div>

                    <div class="form-group">

                        <label class="col-md-3 control-label">外部链接</label>

                        <div class="col-md-3">
                            <g:textField name="applicationUrl" value="${this.product?.applicationUrl}"
                                         class="form-control"/>
                        </div>
                    </div>

                    <div class="hr-line-dashed"></div>

                  %{--  <div class="form-group">
                        <label class="col-md-3 control-label">产品介绍</label>

                        <div class="col-md-3">
                            <g:textArea name="introduction" value="${this.product?.introduction}" class="form-control"
                                        rows="25" cols="15"/>
                        </div>
                    </div>--}%
                    <div class="form-group">
                        <g:field name="introduction" id="introduction"
                                 value="${this.product?.introduction}"
                                 type="hidden"/>
                        <label class="col-md-3 control-label">产品介绍</label>
                        <div class="col-md-3">
                            <div id="productSummernote">${this.product?.introduction}</div>
                        </div>

                    </div>

                    <div class="hr-line-dashed"></div>

                    <div class="form-group">
                        <div class="col-md-offset-4">
                            <button type="button" class="btn btn-info" id="productBtn">保存</button>
                        </div>
                    </div>
                </g:form>
            </div>
        </div>
    </div>
</div>
<script>
    $(function () {
        var text =  $("#introduction").val();
        $('#productSummernote').summernote({
            minHeight: 400,
            maxHeight: 800,
//            lang: 'zh-CN',
            toolbar: [
                ['style', ['style']],
                ['fontname', ['fontname','fontsize','forecolor']],
                ['color', ['color']],
                ['para', ['ul', 'ol', 'paragraph','height']],
                ['view', ['fullscreen', 'codeview', 'help']],
                ['font', ['bold', 'underline', 'clear','strikethrough', 'superscript', 'subscript']],
                ['insert', ['link', 'picture','table','hr']]
            ]
        }).summernote('code', text);

        $("#productBtn").click(function () {
            var markupStr = $('#productSummernote').summernote('code');
            $("#introduction").val(markupStr);
            $(".productForm").submit();
        });
    })
</script>
</body>
</html>
